package edu.harding.redzone;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.View;

public class MainActivity extends Activity
{
	protected Dialog mSplashDialog;
	protected boolean mFirstTime = true;
	private final int SECONDS = 5000;
	private final String MIME = "image/png";
	private final String MODE_PREF = "modePref";
	private final String COLOR_PREF = "colorPref";
	private String mModePref;
	private static String mColorPref;

	public static String PlayerColor()
	{
		return mColorPref;
	}

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		if (mFirstTime == true)
			showSplashScreen();

		setContentView(R.layout.main);
	}

	private void showSplashScreen()
	{
		mSplashDialog = new Dialog(this, R.style.SplashScreen);
		mSplashDialog.setContentView(R.layout.splash);
		mSplashDialog.setCancelable(false);
		mSplashDialog.show();

		final Handler handler = new Handler();
		handler.postDelayed(new Runnable()
		{
			public void run()
			{
				removeSplashScreen();
				mFirstTime = false;
			}

		}, SECONDS);
	}

	private void removeSplashScreen()
	{
		if (mSplashDialog != null)
		{
			mSplashDialog.dismiss();
			mSplashDialog = null;
		}
	}

	public void onCreatePlayButtonClick(View view)
	{
		SharedPreferences sharedPrefs = PreferenceManager
				.getDefaultSharedPreferences(this);
		
		mModePref = sharedPrefs.getString(MODE_PREF, "1").toString();
		mColorPref = sharedPrefs.getString(COLOR_PREF, "1").toString();

		if (mModePref.equals("1"))
			startActivity(new Intent(this, OffenseModeActivity.class));
		else if (mModePref.equals("2"))
			startActivity(new Intent(this, DefenseModeActivity.class));
	}

	public void onSendPlayButtonClick(View view)
	{
		Intent intent = new Intent(android.content.Intent.ACTION_SEND);
		intent.setType(MIME);
		startActivity(intent);
	}

	public void onViewPlayButtonClick(View view)
	{
		startActivity(new Intent(this, ViewModeActivity.class));
	}

	public void onSettingsButtonClick(View view)
	{
		startActivity(new Intent(this, SettingsActivity.class));
	}
}
